//
//  Home_CollectionViewCellNews.m
//  EggSteward
//
//  Created by 王道林 on 16/8/30.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "Home_CollectionViewCellNews.h"
#import "BaseLabel.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "Home_NewsModel.h"
@interface Home_CollectionViewCellNews ()
@property (nonatomic, strong) UIImageView *imageview;
@property (nonatomic, strong) BaseLabel *lableTitle;
@property (nonatomic, strong) BaseLabel *labelContent;
@end


@implementation Home_CollectionViewCellNews

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}


- (void)createSubView
{
    _imageview = [[UIImageView alloc] init];
    [self.contentView addSubview:_imageview];
    
    _lableTitle = [[BaseLabel alloc] init];
    [self.contentView addSubview:_lableTitle];
    _lableTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    _labelContent = [[BaseLabel alloc] init];
    [self.contentView addSubview:_labelContent];

}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [_imageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(10);
        make.width.mas_equalTo(64);
        make.top.mas_equalTo(self.contentView.mas_top).offset(8);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-8);
    }];
    [_lableTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_imageview.mas_right).offset(10);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-10);
        make.top.mas_equalTo(self.contentView.mas_top).offset(8);
        make.height.mas_equalTo(_imageview.mas_height).multipliedBy(0.4);
    }];
    [_labelContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_imageview.mas_right).offset(10);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-10);
        make.bottom.mas_equalTo(_imageview.mas_bottom);
        make.height.mas_equalTo(_imageview.mas_height).multipliedBy(0.4);
    }];

}

- (void)setModel:(Home_NewsModel *)model
{
    _model = model;
    [_imageview sd_setImageWithURL:[NSURL URLWithString:_model.cms_pic] placeholderImage:[UIImage imageNamed:@"80"]];
    _lableTitle.text = _model.cms_title;
    _labelContent.text = _model.descriptions;
}


@end
